##############################################################################
#
# Report.pm
# =========
#
# Author: Steven Liang <stliang@gmail.com>
#
# Purpose:
#   Parent of sub classes that facilitate test result reporting
#
# Assumptions:
#   1.) Sub classes must override genSummary and saveTestReport  methods
#
# Supported methods:
#   new($_release, $_build);
#   release (;$_release);
#   build (;$_build);
#   testReport (;$_testReport);
#   appendTestReport($_testReport);
#   total(;$_total);
#   pass(;$_pass);
#   incrPass(;$number);
#   fail(;$_fail);
#   incrFail(;$number);
#   getNotRun();
#   saveTestReport($testScriptName);
#   genSummary();
#
# Note:
#   Variable after ";" is optional variable and value after "||" is 
#   default value
#
##############################################################################

package Report;
$VERSION = 1.01;

use strict;
use AutoTest::Exceptions;
use vars qw($_release $_build $_testReport $_total $_pass $_fail $_notRun);

# Constructor: new
# Purpose:     Instantiate a Report object
# Parameters:
#       1.) _release : Test image release information
#       2.) _build   : Test image build information
# Returns:    An instance of Report class
sub new ($$) {
	my $class = shift;
	my $self = { };
        $self->{"_release"} = shift;
        $self->{"_build"} = shift;
        $self->{"_testReport"} = "";
        $self->{"_total"} = 0;
        $self->{"_pass"} = 0;
        $self->{"_fail"} = 0;
        $self->{"_notRun"} = 0;
	bless $self, $class;
	return $self;
}

# Method:	release
# Purpose:	Get or set release image information
# Parameters:
#       1.) release : Test image release information
# Returns:	value of _release
sub release ($) {
    my $self = shift;
    $self->{"_release"} = $_[0] if defined($_[0]);
    return $self->{"_release"};
}

# Method:	build
# Purpose:	Get or set build image information
# Parameters:
#       1.) build : Test image build information
# Returns:	value of _build
sub build ($) {
    my $self = shift;
    $self->{_build} = $_[0] if defined($_[0]);
    return $self->{_build};
}

# Method:	testReport
# Purpose:	Get or set testReport 
# Parameters:
#       1.) testReport : Test report from test script
# Returns:	value of _testReport
sub testReport ($) {
    my $self = shift;
    $self->{_testReport} = $_[0] if defined($_[0]);
    return $self->{_testReport};
}

# Method:       appendTestReport
# Purpose:      Append test report 
# Parameters:
#       1.) testReport : Test report to addpend
# Returns:      Void
sub appendTestReport ($) {
    my $self = shift;
    $self->{_testReport} .= "$_[0]\n" if defined($_[0]);
}

# Method:	total
# Purpose:	Get or set total 
# Parameters:
#       1.) total : Total number of test cases 
# Returns:	value of _total
sub total ($) {
    my $self = shift;
    $self->{_total} = $_[0] if defined($_[0]);
    return $self->{_total};
}

# Method:	pass
# Purpose:	Get or set pass 
# Parameters:
#       1.) pass : Number of test cases pass
# Returns:	value of _pass
sub pass ($) {
    my $self = shift;
    $self->{_pass} = $_[0] if defined($_[0]);
    return $self->{_pass};
}

# Method:       incrPass
# Purpose:      Increment the pass count by input value
# Parameters:
#       1.) number : The amount to add to pass count
# Returns:      value of _pass
sub incrPass ($) {
    my $self = shift;
    if (defined($_[0])) {
        $self->{_pass} += $_[0];
    } else {
        $self->{_pass} += 1;
    }
    return $self->{_pass};
}

# Method:       fail
# Purpose:      Get or set fail
# Parameters:
#       1.) fail : Number of test cases fail
# Returns:      value of _fail
sub fail ($) {
    my $self = shift;
    $self->{_fail} = $_[0] if defined($_[0]);
    return $self->{_fail};
}

# Method:       incrFail
# Purpose:      Increment the fail count by pass in value
# Parameters:
#       1.) number : The amount to add to fail count
# Returns:      value of _fail
sub incrFail ($) {
    my $self = shift;
    if (defined($_[0])) {
	$self->{_fail} += $_[0];
    } else {
	$self->{_fail} += 1;
    }
    return $self->{_fail};
}

# Method:       getNotRun
# Purpose:      Read only method of _notRun value
# Parameters:	None
# Returns:      value of _notRun
sub getNotRun () {
    my $self = shift;
    $self->{_notRun} = $self->{_total} - ($self->{_pass} + $self->{_fail});
    return $self->{_notRun};
}

# Method:	saveTestReport
# Purpose:	Save test report
# Parameters:
#	1.) testScriptName : The name of test script that generated the test report
# Returns:	Void
sub saveTestReport ($) {
}

# Method:	genSummary
# Purpose:	Generate a summary report of all tests done
#		on specified release and build
# Parameters:	None
# Returns:	Void
sub genSummary () {
}
